package com.wwwarehouse.usercenter.fragment.permissiondistribute;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.authoritydistribute.ScanCardAuthResponseBean;
import com.wwwarehouse.usercenter.constant.UserCenterConstant;


/**
 * @author : mundane
 * @time : 2017/9/24 11:28
 * @description :
 * @file : AuthorityReceiveFailFragment.java
 */

public class AuthorityReceiveFailFragment extends BaseFragment {

	private ScanCardAuthResponseBean mScanCardAuthResponse;
	private View mBtnFailDetail;
	private View mBtnIKnow;

	public static AuthorityReceiveFailFragment newInstance(String data) {
		AuthorityReceiveFailFragment fragment = new AuthorityReceiveFailFragment();
		Bundle bundle = new Bundle();
		bundle.putString(UserCenterConstant.KEY_AUTH_RECEIVE_DATA, data);
		fragment.setArguments(bundle);
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle bundle = getArguments();
		if (bundle != null) {
			String data = bundle.getString(UserCenterConstant.KEY_AUTH_RECEIVE_DATA);
			mScanCardAuthResponse = JSON.parseObject(data, ScanCardAuthResponseBean.class);
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_fail_receive_authority, container, false);
		return view;
	}

	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		// findViewById
		mBtnFailDetail = $(R.id.btn_fail_detail);
		mBtnIKnow = $(R.id.btn_i_know);
		mBtnIKnow.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				popFragment();
			}
		});
		if (mScanCardAuthResponse != null) {
			final String processId = mScanCardAuthResponse.processId;
			mBtnFailDetail.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					pushFragment(AuthorityDistributeFailAuthDetailPageFragment.newInstance(processId, 1));
				}
			});
		}

	}

	@Override
	public void setTitle() {
		if (peekFragment() instanceof AuthorityReceiveFailFragment) {
			mActivity.setTitle("权限接收");
		}
	}

	@Override
	public void requestDatas() {

	}
}
